﻿
using System ;

using MskEdit.Sdk ;


namespace MskEdit.Dxf.Model
{

    public class DxfBlocks : DxfStructBase
    {
        private Lazy<DxfBlock[]>  blocks_ ;


        public DxfBlocks( string[] allLines, SdkSubrange subrange ) : base( allLines, subrange ) {
            blocks_ = new Lazy<DxfBlock[]>( () => { return DxfCollection<DxfBlock>.getItems( allLines, subrange, DxfBlock.TryFrom ) ; } ) ;
        }
        
        
        public string TryGetAttrdefPrompt( string blockTag, string attribTag, string fallbackValue ) {
        
            string prompt = null ;
            
            foreach ( DxfBlock dxfBlock in blocks_.Value ) {
            
                if ( ! blockTag.Equals( dxfBlock.Name ) )
                    continue ;
                    
                prompt = dxfBlock.TryGetAttrdefPrompt( attribTag, null ) ;
                if ( prompt != null )
                    break ;
            }
                
            if ( prompt == null )
                return fallbackValue ;
                
            return prompt ;
        }
        
        
        public DxfBlock[] Blocks {
            get { return blocks_.Value ; }
        }
    }
}
